package com.activity;

import android.os.Bundle;

import com.activity.bean.SysTemBean;
import com.api.viewModel.LoginVM;
import com.donkingliang.groupedadapter.adapter.GroupedRecyclerViewAdapter;
import com.donkingliang.groupedadapter.holder.BaseViewHolder;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.activity.widget.Dialog;
import com.example.apple.ddhr_new.adapter.SystemAdapter;

import com.example.apple.ddhr_new.utils.ActivityUtil;
import com.example.lzbase.BaseViewModelActivity;

import java.util.ArrayList;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;

public class SettingActivity extends BaseViewModelActivity<LoginVM> {


    @BindView(R.id.recycle_view)
    RecyclerView recycleView;
    private SystemAdapter adapter;
    private SysTemBean mcache;

    @Override
    protected int titleText() {
        return R.string.shizhi;
    }

    @Override
    protected void created(@Nullable Bundle savedInstanceState) {


        super.created(savedInstanceState);
        recycleView.setLayoutManager( new LinearLayoutManager(this));
        SystemAdapter systemAdapter = new SystemAdapter(this,SystemAdapter.RecycleViewType.GROUP);

        adapter = systemAdapter;

        ArrayList data1 = new ArrayList();
        SysTemBean mima = new SysTemBean(getString(R.string.xiugai_mima),SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        mima.subTitle = "";
        data1.add(mima);
        adapter.getData().add(data1);

        ArrayList data2 = new ArrayList();
        SysTemBean push = new SysTemBean(getString(R.string.tuisong_shezhi),SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);

        push.subTitle = "";
        data2.add(push);


        SysTemBean cache = new SysTemBean(getString(R.string.qingchu_huancun),SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);
        mcache= cache;
        cache.subTitle = App.getCacheSize(this);
        data2.add(cache);
        adapter.getData().add(data2);


        ArrayList data3 = new ArrayList();
        SysTemBean advise = new SysTemBean(getString(R.string.yijian_fankui),SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);

        advise.subTitle = "";
        data3.add(advise);

        SysTemBean about = new SysTemBean(getString(R.string.guanyu),SysTemBean.SysTemBeanType.TYPE_SUBTITLE_ARROW);

        about.subTitle = "";
        data3.add(about);
        adapter.getData().add(data3);

        recycleView.setAdapter(adapter);
        adapter.setOnChildClickListener(new GroupedRecyclerViewAdapter.OnChildClickListener() {
            @Override
            public void onChildClick(GroupedRecyclerViewAdapter adapter, BaseViewHolder holder, int groupPosition, int childPosition) {
                if(groupPosition==1){
                    if(childPosition==1){
                        viewModel.progress.setValue(true);

                        App.cleanCache(SettingActivity.this);
                        mcache.subTitle =App.getCacheSize(SettingActivity.this);
                        adapter.notifyChildChanged(0,1);
                        viewModel.progress.setValue(false);
                    }
                }else if(groupPosition==0){
                    if(childPosition==0){
                            ActivityUtil.startActivity(SettingActivity.this,ChangePwdActivity.class);
                    }
                }

            }
        });

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }



    @OnClick(R.id.btn_denglu)
    public void onViewClicked() {

        Dialog.alert(this, "是否退出登录?", "", new Dialog.OnDialogOkClickListener() {
            @Override
            public void onClick(Object o) {

            }
        }, new Dialog.OnDialogOkClickListener() {
            @Override
            public void onClick(Object o) {
                App.getInstance().setAccount(null);
                ActivityUtil.startLoginActivity(SettingActivity.this);
            }
        });
    }
}
